package com.File;

import java.io.*;
import java.util.Arrays;

public class BufferedCopy_ {
    public static void main(String[] args) throws IOException {
        //BufferedReader 和BufferedWrite 是按照字符操作的
        //不要操作二进制文件,可能造成文件损坏
        String srcFilePath = "d:\\new.txt";
        String destFilePath = "d:\\new2.txt";
        BufferedReader bufferedReader = null;
        BufferedWriter bufferedWriter = null;
        String line;
        try {
            bufferedReader = new BufferedReader(new FileReader(srcFilePath));
            bufferedWriter = new BufferedWriter(new FileWriter(destFilePath));
            while ((line = bufferedReader.readLine()) != null) {
                bufferedWriter.write(line);
                bufferedWriter.newLine();
            }
            System.out.println("Copy");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            if (bufferedReader != null) {
                bufferedReader.close();
            }
            if (bufferedWriter != null) {
                bufferedWriter.close();
            }

        }
    }
}
